/**
 * fileName: TestTag.java
 *     Date: 2012-4-27
 **/
package com.stranger.common.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * @author stranger.lin
 *
 * @时间  2012-4-27
 */
public class TestTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String id;
	private String name;
	private List<Object> list=null;
	private 	JspWriter out;
	@Override
	public int doStartTag() throws JspException {
		
		try {
			out=pageContext.getOut();
			list=new ArrayList<Object>();
			list.add("这是我第一个标签");
		
			StringBuffer ops=new StringBuffer("<select id=\""+id+"\" name=\""+name+"\">");
			if (list!=null) {
				for (int i = 0; i < list.size(); i++) {
					ops.append("<option value=\""+list.get(i)+"\">"+list.get(i)+"</option>");
				}
				ops.append("</select>");
			}
			out.print(ops);
			//out.flush();
			//out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	
		return SKIP_BODY;
	}
	
	@Override
	public int doEndTag() throws JspException {
		try {
			if(out!=null){
			  out.flush();	
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SKIP_BODY;
	}
	

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}



	public List<Object> getList() {
		return list;
	}



	public void setList(List<Object> list) {
		this.list = list;
	}
	
	
	
}
